package com.example.demo.service.imp;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.entity.Group;
import com.example.demo.mapper.GroupMapper;
import com.example.demo.service.GroupService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GroupServiceImp implements GroupService {
    @Resource
    private GroupMapper groupMapper;

    @Override
    public Object selectByUsername(String groupName) {
        return groupMapper.selectByUsername(groupName);
    }

    @Override
    public void insert(Group group) {
        groupMapper.insert(group);
    }

    @Override
    public void updateById(Group group) {
        groupMapper.updateById(group);
    }

    @Override
    public void deleteById(Long id) {
        groupMapper.deleteById(id);
    }

    @Override
    public Page<Group> selectPage(Integer pageNum, Integer pageSize, String search) {
        LambdaQueryWrapper<Group> wrapper = Wrappers.<Group>lambdaQuery();
        if(StrUtil.isNotBlank(search)){
            wrapper.eq(Group::getGroupId,search).or();
            wrapper.like(Group::getGroupName, search).or();

        }
        return groupMapper.selectPage(new Page<>(pageNum, pageSize),wrapper);
    }

    @Override
    public List<Group> selectAll(Group group) {
        return groupMapper.selectAll(group);
    }


}
